package com.sunny.design.singleton.thread;

/**
 * 伪线程单例
 *
 * @author Sunny
 * @date 2019/12/29 17:05
 */
public class ThreadSingleton {

    private ThreadSingleton(){}

    private static final ThreadLocal<ThreadSingleton> LOCAL = ThreadLocal.withInitial(ThreadSingleton::new);

    /**
     * 该方法是在单个线程中保持唯一, 不同线程有各自唯一的一份对象
     */
    public static ThreadSingleton getInstance() {
        return LOCAL.get();
    }
}
